<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>x-admin</title>
    <link rel="stylesheet" href="/static/xadmin/lib/layui/css/layui.css">
    <style>
    </style>
    <script>
        /^http(s*):\/\//.test(location.href) || alert('请先部署到 localhost 下再访问');
    </script>
</head>
<body>
<div class="layui-form">
    <table class="layui-table">
        <input type="hidden" id="id" value="{$find.id}">
        <tr>
            <td>
                <label class="layui-form-label">文章类型</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <select name="article_cate" id="article_cate" lay-verify="required" lay-search>
                        <option value="0">=请选择=</option>
                        {volist name="list" id="vo"}
                        <option value="{$vo.id}" {if condition="$vo.id eq $find.article_cate"}selected{/if} >{$vo.cate_name}</option>
                        {/volist}
                    </select>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">文章标题</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <input type="text" id="title" value="{$find.title}" required  lay-verify="required" placeholder="请输入文章标题" autocomplete="off" class="layui-input">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">文章说明</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <textarea placeholder="请输入说明" class="layui-textarea"  id="remark" name="desc">
                         {$find.remark}
                    </textarea>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">文章内容</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <!--//采用吧 百度的富文本编辑-->
                   <!-- <script id="container" name="content" type="text/plain">
                        {$find.content}
                    </script>-->

                    <textarea id="editor_id" name="editor" style="display: none;"> {$find.content}</textarea>
                </div>

            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">文章属性</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <input type="radio" name="is_reprint" value="1" title="原创" {if condition="$find.is_reprint eq 1 "}checked{/if}>
                    <input type="radio" name="is_reprint" value="2" title="转载"  {if condition="$find.is_reprint eq 2 "}checked{/if}>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">转载地址</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <input type="text" id="link_url" value="{$find.link_url}" required lay-verify="required" placeholder="请输入转载地址" autocomplete="off" class="layui-input">
                    <span style="color: red">如果该文章是转载请填写转载地址</span>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">文章状态</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="发布"  {if condition="$find.status eq 1 "}checked{/if}>
                    <input type="radio" name="status" value="2" title="草稿箱" {if condition="$find.status eq 2 "}checked{/if} >
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">排序</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <input type="number" min="0" value="{$find.sort}" id="sort" required  lay-verify="required" placeholder="请输入排序" autocomplete="off" class="layui-input">
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center">
                <div class="layui-input-block">
                    <!--<button class="layui-btn" onclick="add_sumbit()">立即提交</button>-->
                    <button class="layui-btn" type='submit'>立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </td>
        </tr>
    </table>
</div>
<script src="/static/xadmin/lib/layui/jquery-3.2.1.min.js"></script>
<script src="/static/xadmin/lib/layui/layui.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="/static/ueditor1_4_3_3/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/static/ueditor1_4_3_3/ueditor.all.js"></script>

<script>
    layui.config({
        base: '/static/xadmin/' //静态资源所在路径
    });
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
    });
//    var ue = UE.getEditor('container');
   /* //添加
    function add_sumbit() {
        //获取值
        var article_cate=$("#article_cate").val();
        var id=$("#id").val();
        var title=$("#title").val();
        var remark=$("#remark").val();
        var content=UE.getEditor('container').getContent()
        var link_url=$("#link_url").val();
        var is_reprint = $('input[name=is_reprint]:checked').val();
        var status = $('input[name=status]:checked').val();
        var sort=$("#sort").val();
        $.post(
            "{:url('admin/article/edit')}",
            {id:id,article_cate:article_cate,title:title,remark:remark,content:content,link_url:link_url,
                is_reprint:is_reprint,status:status,sort:sort},
            function (data) {
                console.log(data);
                if(data.code==1){
                    layer.msg(data.msg,{icon:1});
                    setTimeout(function () {
                        parent.layer.closeAll();
                        parent.location.reload();
                    },1500);
                }else{
                    layer.msg(data.msg,{icon:2});
                }
            });

    }*/
    layui.use(['form', 'layedit','jquery','layer','laydate','upload'],function()  {
        var form = layui.form
            , layer = layui.layer//弹层
            , layedit = layui.layedit//编辑器
            , laydate = layui.laydate//日期
            , upload = layui.upload//上传
            ,$ = layui.jquery;

        //上传图片,必须放在 创建一个编辑器前面
        /*      layedit.set({
                  uploadImage: {url: "{:url('admin/upload/upload_img_oss',['type'=>'admin'])}", type: 'post'}
              });*/
        layedit.set({
            uploadImage: {
                url: "{:url('admin/upload/img_save_layui',['type'=>'article'])}" //接口url
                ,type: '' //默认post
            }
        });
        //创建一个编辑器
        CONTENT = layedit.getContent(index);
        //编辑器外部操作
        var active = {
            content: function(){
                alert(layedit.getContent(index)); //获取编辑器内容
            }
            ,text: function(){
                alert(layedit.getText(index)); //获取编辑器纯文本内容
            }
            ,selection: function(){
                alert(layedit.getSelection(index));
            }
        };


        $('.site-demo-layedit').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //自定义工具栏
        var index= layedit.build('editor_id', {
            tool: [
                'strong' //加粗
                ,'italic' //斜体
                ,'underline' //下划线
                ,'del' //删除线

                ,'|' //分割线

                ,'left' //左对齐
                ,'center' //居中对齐
                ,'right' //右对齐
                ,'link' //超链接
                ,'unlink' //清除链接
                ,'face' //表情
                ,'image' //插入图片
                ,'help' //帮助
            ]
            ,height: 400
        })
        layedit.sync(index);

        $('button[type=submit]').click(function(){
            var id=$("#id").val();
            //获取编辑器的值
            var content=layedit.getContent(index);
            //获取值
            var article_cate=$("#article_cate").val();
            var title=$("#title").val();
            var remark=$("#remark").val();
            var link_url=$("#link_url").val();
            var is_reprint = $('input[name=is_reprint]:checked').val();
            var status = $('input[name=status]:checked').val();
            var sort=$("#sort").val();
            $.post(
                "{:url('admin/article/edit')}",
                {id:id,article_cate:article_cate,title:title,remark:remark,content:content,link_url:link_url,
                    is_reprint:is_reprint,status:status,sort:sort},
                function (data) {
                    console.log(data);
                    if(data.code==1){
                        layer.msg(data.msg,{icon:1});
                        setTimeout(function () {
                            parent.layer.closeAll();
                            parent.location.reload();
                        },1500);
                    }else{
                        layer.msg(data.msg,{icon:2});
                    }
                });

        });


    });


</script>
</body>
</html>
